{include file='common/head' /}
    <body>
        　　<script src="__LAYUI__/jq.js"></script>


        <div class="x-nav">
          <span class="layui-breadcrumb">
              <a><cite>店铺管理</cite></a>
              <a><cite>店铺列表</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <!--搜索-->
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <!--id-->
                                <div style="width:80px;" class="layui-inline layui-show-xs-block">
                                    <input type="text" name="id"  placeholder="序号" autocomplete="off" class="layui-input" value="{$get.id|default=''}">
                                </div>
                                <!--用户序号-->
                                <div style="width:80px;" class="layui-inline layui-show-xs-block">
                                    <input type="text" name="uid"  placeholder="用户序号" autocomplete="off" class="layui-input" value="{$get.uid|default=''}">
                                </div>
                                <!--名称-->
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="name"  placeholder="名称" autocomplete="off" class="layui-input" value="{$get.name|default=''}">
                                </div>
                                <!-- 排序值 -->
                                <div style="width:80px;" class="layui-inline layui-show-xs-block">
                                    <input type="number" name="sort"  placeholder="排序值" autocomplete="off" class="layui-input" value="{$get.sort|default=''}">
                                </div>
                                <!--申请状态-->
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="apply_status" lay-verify="" lay-search>
                                        <option value="">申请状态</option>
                                        {volist name="apply_status_arrs" id="v"}
                                        <option value="{$key}" {if condition="strlen($get['apply_status']) >= 1 && $get['apply_status'] == $key"}selected{/if}>{$v}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <!--是否开启-->
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="is_open" lay-verify="" lay-search>
                                        <option value="">是否开启</option>
                                        <option value="0" {if condition="strlen($get['is_open']) >= 1 && $get['is_open'] == 0"}selected{/if}>关闭</option>
                                        <option value="1" {if condition="$get['is_open'] == 1"}selected{/if}>开启</option>
                                    </select>
                                </div>
                                <!-- 分页数据 -->
                                <div class="layui-inline layui-show-xs-block" style="width: 150px;">
                                    <select name="limit">
                                        <option value="" selected>分页数据</option>
                                        <option value="10" {if condition="$get['limit'] == 10"}selected{/if}>10条</option>
                                        <option value="20" {if condition="$get['limit'] == 20"}selected{/if}>20条</option>
                                        <option value="30" {if condition="$get['limit'] == 30"}selected{/if}>30条</option>
                                        <option value="50" {if condition="$get['limit'] == 50"}selected{/if}>50条</option>
                                        <option value="100" {if condition="$get['limit'] == 100"}selected{/if}>100条</option>
                                        <option value="150" {if condition="$get['limit'] == 150"}selected{/if}>150条</option>
                                        <option value="200" {if condition="$get['limit'] == 200"}selected{/if}>200条</option>
                                    </select>
                                </div>
                                <!--日期选择-->
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="开始日" name="start" id="start" value="{$get.start|default=''}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input class="layui-input"  autocomplete="off" placeholder="截止日" name="end" id="end" value="{$get.end|default=''}">
                                </div>
                                <!--按钮-->
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="iconfont">&#xe69d;</i> 批量删除</button>
                            <button class="layui-btn layui-btn-normal" title="点我批量改变" onclick="pinLiangStatusBtn('is_open')">批量开启/关闭</button>
                            <button class="layui-btn" onclick="xadmin.open('添加店铺','/admin/shop/list_edit','','',true)">
                                <i class="layui-icon"></i>商品
                            </button>
                            <span style="line-height:40px;float: right;">共有数据：{$count} 条</span>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th style="text-align: center;width: 3%">
                                      <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                                    </th>
                                    <th style="text-align: center;width:5%">店铺序号</th>
                                    <th style="text-align: center;width: 10%">名称</th>
                                    <th style="text-align: center;width: 10%">logo</th>
                                    <th style="text-align: center;width:5%">店铺信息</th>
                                    <th style="text-align: center;width: 10%">开启</th>
                                    <th style="text-align: center;width: 10%">状态</th>
                                    <th style="text-align: center;width: 9%">发布时间</th>
                                    <th style="text-align: center;width: 25%">操作</th>
                                  </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="v"}
                                  <tr>
                                    <td style="text-align: center;">
                                      <input type="checkbox" name="id" value="{$v.id}"   lay-skin="primary">
                                    </td>
                                     <td style="text-align: center;">
                                        <span style="cursor: pointer;" onclick="copyCode('{$v.id}')">{$v.id}</span>
                                    </td>
                                    <td style="text-align: center;">
                                        <span style="cursor: pointer;" onclick='copyCode("{$v.name}")'>{$v.name}</span>
                                    </td>
                                    <td style="text-align: center;">
                                        <?php
                                            $logo_url =
                                                strpos($v['logo'],'http') !== false ?
                                                $v['logo'] : 'https://admin.miaommei.com'.$v['logo'];
                                        ?>
                                        <a href="{$logo_url}" target="_blank"><img src="{$logo_url}" height="50"></a>
                                    </td>
                                    <td style="text-align: center;">

                                    </td>
                                      <!-- 状态 -->
                                      <td class="clickStatus" style="text-align: center;" data-id={$v.id} data-title="{$v.is_open == 1 ? '关闭' : '开启'}" data-key="is_open" data-val="{$v.is_open == 1 ? 0 : 1}">
                                        {$v.is_open == 1 ?
                                        '<button type="button" title="点我更改状态" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon ">&#xe605;</i></button>' :
                                        '<button type="button" title="点我更改状态" class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon">&#x1006;</i></button>';
                                        }
                                      </td>
                                    <td style="text-align: center;">
                                        {$apply_status_arrs[$v.apply_status]|default='无'}
                                    </td>
                                    <td style="text-align: center;">{:date('Y-m-d H:i',$v['add_time'])}</td>
                                    <td style="text-align: center;" class="td-manage">
                                        <button class="layui-btn layui-btn layui-btn-xs layui-btn-normal" title="编辑"  onclick="xadmin.open('编辑','/admin/shop/wallet_edit?id={$v.id}',800,600)" href="javascript:;"><i class="layui-icon">&#xe6b1;</i>钱包</button>
                                        {if $v.is_open == 1}<button class="layui-btn layui-btn layui-btn-xs layui-btn-normal" title="关闭"  onclick="closeFun({$v.id},'{$v.name}')" href="javascript:;"><i class="layui-icon">&#xe6b1;</i>关闭</button>{/if}
                                        <button class="layui-btn layui-btn layui-btn-xs layui-btn-normal" title="审核通过"  onclick="checkOk({$v.id},'{$v.name}')" href="javascript:;"><i class="layui-icon">&#xe6b1;</i>审核通过</button>
                                        <button class="layui-btn layui-btn layui-btn-xs layui-btn-normal" title="编辑"  onclick="xadmin.open('编辑','/admin/shop/list_edit?id={$v.id}','','',true)" href="javascript:;"><i class="layui-icon">&#xe642;</i>编辑</button>
                                        <button class="layui-btn-danger layui-btn layui-btn-xs" title="删除" onclick="member_del(this,{$v['id']})" href="javascript:;"><i class="layui-icon">&#xe640;</i>删除</button>
                                    </td>
                                  </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
<style>
   table .moneyFont {
       color:#FF5722;
   }

   .mySelf-lyaui-nav {
       background: transparent;
   }
   .mySelf-lyaui-nav li {
       line-height: 40px!important;
   }
   /*
   .mySelf-lyaui-nav li:hover .layui-nav-child{
        display: block;
       left:-200px!important;
       top:0px!important;;
   }
   */
</style>
    <script>
      layui.use(['form','laydate'], function(){
          var laydate = layui.laydate;
          var  form = layui.form;

          //执行一个laydate实例
          laydate.render({
              elem: '#start' //指定元素
          });

          //执行一个laydate实例
          laydate.render({
              elem: '#end' //指定元素
          });

        // 监听全选
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        });
      });

      /*删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              $.ajax({
                  url:"/admin/shop/list_del",
                  type: "post",
                  data:{id},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          layer.msg('删除成功', {icon: 1,time:1000});
                          $(obj).parents("tr").remove();
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      // 前缀请求地址
      var PREFIX_AJAX_URL = '/admin/shop/list_';

      // _status 状态
      //  pinliang_status 批量状态
      // sortEdit 排序
      // delAll 批量删除

      // 状态值
      var objKeys = {
          // 开启
          is_open: {  // 下标  0 关闭 隐藏  1 开启
              val: [0,1],
              title: ['关闭','开启']
          },
          // 是否跳转
          is_skip: {  // 下标    1 跳转  0 表示 不跳转
              val: [0,1],
              title: ['不跳转','跳转']
          },
      }

      var btnStrs = [
          '<button type="button" title="点我更改状态" class="layui-btn layui-btn-danger layui-btn-xs"><i class="layui-icon">ဆ</i></button>', // 不开启
          '<button type="button" title="点我更改状态" class="layui-btn layui-btn-normal layui-btn-xs"><i class="layui-icon "></i></button>' // 开启
      ];


      $(function(){
          bindClickBtn()
          $(".sortClick").click(function(){
              $(this).parent().find('div').css('display','flex')
              $(this).hide()
              $(this).parent().find('input').focus();
          })

          $(".sortBtn").click(function(){
              var id = $(this).attr('data-id')
              if(!id) return layer.msg('没有该选项',{icon:5})
              var sort = $(this).prev().val()
              if(!sort || sort < 0) return layer.msg('排序输入错误',{icon:5})
              var oldSort = $(this).parent().parent().find('.sortClick').text()
              if(oldSort - 0 == sort - 0) return layer.msg('值不能相同',{icon:5})
              var self = this
              $.ajax({
                  url:PREFIX_AJAX_URL + 'sortEdit',
                  data:{id,sort},
                  dataType: 'json',
                  success:function(res){
                      layer.msg(res.msg || '操作ok',{icon: res.code == 200 ? 6 : 5})
                      if(res && res.data){
                          $(self).parent().parent().find('span').text(sort).show(300)
                          $(self).parent().css('display','none')
                      }
                  },
                  error:function(err){
                      layer.msg('输入错误',{icon:5})
                  }
              })
          })
      })

      // 绑定事件
      function bindClickBtn()
      {
          $("table tbody .clickStatus button").off('click');
          $("table tbody .clickStatus button").click(function(e){
              var self  = this;
              // 拿取到tb
              var tb = $(this).parent()
              var data = {
                  id: $(tb).attr('data-id'),
                  val: $(tb).attr('data-val'),
                  key: $(tb).attr('data-key')
              }
              clickStatusBtn(PREFIX_AJAX_URL+'_status.html',data,{
                  msg: '此商品序号:'+data.id+"-状态为:"+$(tb).attr('data-title')+'？',
                  elem: self
              },toggleBtn);
          })
      }

      /**
       *  将按钮更改为相反的状态
       */
      function toggleBtn(data,self){
          if(self && objKeys[data.key]){
              var i = objKeys[data.key].val.indexOf(data.val - 0)
              if(i >= 0){
                  var tb = $(self).parent()
                  $(self).hide(500,function(){
                      $(tb).html(btnStrs[i])
                      setTimeout(function(){
                          $(self).show(400,function(){
                              bindClickBtn();
                          })
                      },300)
                  })
                  // 目前只有两种状态
                  $(tb).attr('data-val',objKeys[data.key].val[i == 0 ? 1 : 0])
                  $(tb).attr('data-title',objKeys[data.key].title[i == 0 ? 1 : 0])
              }
          }
      }


      //批量删除
      function delAll (argument) {
          var ids = [];
          // 获取选中的id
          $('tbody input[type="checkbox"]').each(function(index, el) {
              if($(this).prop('checked')){
                  ids.push($(this).val())
              }
          });

          if(ids.length == 0 || !ids) return layer.msg('必须选择一项',{icon:5});

          // 弹窗提示中
          layer.confirm('确认要删除吗？',function(index){
              $.ajax({
                  url: PREFIX_AJAX_URL +"delAll",
                  type: "post",
                  data:{id:ids},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          //捉到所有被选中的，发异步进行删除
                          layer.msg('删除成功', {icon: 1,time:1000});
                          $(".layui-form-checked").not('.header').parents('tr').remove();
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      // 三个按钮操作 等
      function pinLiangStatusBtn(key){
          if(!objKeys[key]) return layer.msg('必须选择一项',{icon:5});
          var ids = [];
          // 获取选中的id
          $('tbody input[type="checkbox"]').each(function(index, el) {
              if($(this).prop('checked')){
                  ids.push($(this).val())
              }
          });
          if(!ids || ids.length == 0) return layer.msg('必须选择一项',{icon:4});
          // 数据
          var obj = {
              ids,
              key
          }
          layer.confirm('确认批量操作？',{title:'批量操作',icon:3,btn:[objKeys[key].title[1],objKeys[key].title[0],'取消']},function(index){
              obj.val = objKeys[key].val[1]
              ajaxFun(PREFIX_AJAX_URL+'pinliang_status.html',obj,'post',function(){
                  window.location.href = window.location.href
              })
              layer.close(index)
          },function(index){
              obj.val = objKeys[key].val[0]
              ajaxFun(PREFIX_AJAX_URL+'pinliang_status.html',obj,'post',function(){
                  window.location.href = window.location.href
              })
          })
      }

      // 是否审核通过
      function checkOk(id,title){
          // 弹窗提示中
          layer.confirm('确认将店铺名：'+title+',审核通过吗？',{title:'审核操作',icon:3},function(index){
              $.ajax({
                  url: '/admin/shop/check',
                  type: "post",
                  data:{id},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          //捉到所有被选中的，发异步进行删除
                          layer.msg(res.msg ||'审核ok', {icon: 1,time:1000});
                          window.location = window.location
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      // 关闭店铺
      function closeFun(id,title){
          // 弹窗提示中
          layer.confirm('确认将店铺名：'+title+',关闭下架吗？',{title:'关闭操作-所有此店铺商品都将下架',icon:3},function(index){
              $.ajax({
                  url: '/admin/shop/close',
                  type: "post",
                  data:{id},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          //捉到所有被选中的，发异步进行删除
                          layer.msg(res.msg ||'关闭ok', {icon: 1,time:1000});
                          window.location = window.location
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }



      // ajax封装
      function ajaxFun(url,obj,type = 'post',fun,errFun,elem){
          var s = layer.msg('加载中...',{icon:4,time:999999})
          $.ajax({
              url,
              type,
              data:obj,
              dataType:"json",
              success:function (res) {
                  if(res.code == 200){
                      layer.msg(res.msg ? res.msg : '操作ok', {icon: 1,time:1000});
                  }else{
                      layer.alert(res.msg, {icon:2,time:1000});
                  }
                  layer.close(s)
                  if(fun) fun(res.data,elem);
              },
              error:function(e){
                  layer.close(s)
                  layer.alert("网络错误", {icon:5,time:1000});
                  if(errFun) errFun(res);
              },
          });
      }


      /**
       * 封装弹窗中的数据信息
       * 参数：  请求地址， 请求数据， 标题，成功回调函数，错误回调函数
       */
      function clickStatusBtn(url,obj,options,fun= false,errFun = false){
          var s = layer.msg('加载中...',{icon:4,time:999999})
          layer.confirm(options.msg,{title: options.title ? options.title : '操作提示',icon: options.icon ? options.icon : 3},function(index){
              $.ajax({
                  url,
                  type: "post",
                  data:obj,
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          //捉到所有被选中的，发异步进行删除
                          layer.msg(res.msg ? res.msg : '操作ok', {icon: 1,time:1000});
                          //$(".layui-form-checked").not('.header').parents('tr').remove();
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                      layer.close(s)
                      if(fun) fun(res.data,options.elem);
                  },
                  error:function(e){
                      layer.close(s)
                      layer.alert("网络错误", {icon:5,time:1000});
                      if(errFun) errFun(res);
                  },
              });
          });
      }
    </script>

<script>
    function copyCode(title){
        $("#copyText").val(title)
        setTimeout(function(){
            var copy=document.getElementById("copyText");
            copy.select(); // 选择对象
          document.execCommand("Copy"); // 执行浏览器复制命令
        },50)
      layer.msg('复制成功：'+title,{icon: 6})
    }
  </script>
  <input id="copyText" type="text" style="width: 1px;opacity: 0;height:1px;position: absolute;"/>
{include file='common/scroll' /}    
{include file='common/footer' /}